package com.silence.gmall.product.controller;

import com.silence.gmall.annotations.Log;
import com.silence.gmall.base.Result;
import com.silence.gmall.base.TableDataInfo;
import com.silence.gmall.product.domain.repository.SpuInfoRepository;
import com.silence.gmall.product.dto.SpuInfoDto;
import com.silence.gmall.product.service.SpuInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Author silence
 * @Description 商品表控制器
 * @Date 2025-08-17 16:28:16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/product")
public class SpuController {

    /**
     * SpuInfoService 的注入
     */
    private final SpuInfoService spuInfoService;

    /**
     * SpuInfoRepository 的注入
     */
    private final SpuInfoRepository spuInfoRepository;

    /**
     * 获取spu分页列表
     *
     * @param page        当前页码
     * @param limit       当前页数
     * @param category3Id 三级分类ID
     * @return spu分页列表
     */
    @GetMapping("/{page}/{limit}")
    @Log(interfaceName = "获取spu分页列表")
    public Result<TableDataInfo<SpuInfoDto>> pageSpuInfo(@PathVariable("page") Long page,
                                                                                       @PathVariable("limit") Long limit,
                                                                                       @RequestParam("category3Id") String category3Id) {
        return Result.build(spuInfoRepository.pageSpuInfo(page, limit, category3Id));
    }

    /**
     * 添加spu
     *
     * @param reqVo spu信息
     * @return 结果
     */
    @PostMapping("/saveSpuInfo")
    @Log(interfaceName = "添加spu")
    public Result<Void> saveSpuInfo(@RequestBody SpuInfoDto reqVo) {
        spuInfoService.saveSpuInfo(reqVo);
        return Result.build();
    }
}